<template>
  <div>
    <el-form :model="user" :rules="rules" ref="userForm" :hide-required-asterisk=true>
      <el-form-item label="账号" prop="username">
        <el-input
            v-model="user.account"
            clearable
            size="default"
            style="margin: 10px 0"
            prefix-icon="el-icon-user"
            placeholder="请输入账号"
        ></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password" :hide-required-asterisk=true>
        <el-input
            v-model="user.password"
            clearable
            size="default"
            style="margin: 10px 0"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
            show-password
        ></el-input>
      </el-form-item>
    </el-form>
    <div style="margin: 30px 0; text-align: center">
      <el-button type="primary" size="default" autocomplete="off" @click="login">登录</el-button>
      <!--<el-button type="text" size="medium" autocomplete="off" style="margin-left: 170px" @click="forget_passwd">
        忘记密码？
      </el-button>-->
    </div>
  </div>


</template>

<script>
export default {
  name: "login",
  data() {
    return {
      user: {
        account: "",
        password: "",
        group:1
      },
      checked: false,
      rules: {
        account: [
          {required: true, message: "请输入用户名", trigger: "blur"},
          {min: 5, max: 10, message: "长度在 5 到 10 个字符之间", trigger: "blur"},
        ],
        password: [
          {required: true, message: "请输入密码", trigger: "blur"},
          {min: 5, max: 12, message: "长度在 5 到 12 个字符之间", trigger: "blur"},
        ],
      },
    };
  },
  mounted() {
    if (localStorage.getItem("news")) {
      this.form = JSON.parse(localStorage.getItem("news"))
      this.checked = true
    }
  },
  computed: {
    currentPathName() {
      return this.$route.path
    }
  },
  methods: {
    login() {
      if(this.user.group==1)this.$router.push("/post")
      else this.$router.push("/manage")
      /*this.$refs.userForm.validate((valid) => {
        if (valid) {  //表单校验合法
          this.rq.post("/login", this.user).then(res => {
            if (res.code === '200') {
              localStorage.setItem("user", JSON.stringify(res.data));  //存储用户信息到浏览器
              this.$message.success("登录成功")
              if(this.user.group==1)
                this.$router.push("/post")
              else if(this.user.group==2)
                this.$router.push("/manage")
            } else {
              // setToken(res.data.token)
              // localStorage.setItem("USERNAME", res.data.username)
              this.$message.error("用户名或密码错误")
            }
          }).catch((err) => {
            this.$message.error("未知错误")
          })
        }
      })*/
    },
  },
}

</script>

<style scoped>

</style>
